package ui.fragment.minefragment;

import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import adapter.MyPointsDeatilAdapter;
import base.BaseBean;
import base.fragment.BaseNetFragment;
import bean.MyPointDetailBean;
import bean.MyPointDetailListBean;
import bean.NoteCategoryBean;
import student.andlei.com.student.R;
import ui.fragment.MineFragment;
import utils.GsonUtils;

/**
 * 积分详细
 */
public class IntegralDetailFragment extends BaseNetFragment {
    private ImageView iv_back;
    private RecyclerView recyclerView;
    private List<MyPointDetailListBean> lists = new ArrayList<>();
    private MyPointsDeatilAdapter adapter;
    public static Fragment getInstance() {
        return new IntegralDetailFragment();
    }
    @Override
    public void success(String action, BaseBean baseBean) {
        lists  = GsonUtils.getInstance(getActivity()).parseHaveHeaderJArray(baseBean,MyPointDetailListBean.class,"list");
                //.parseNoHeaderJArray(baseBean,MyPointDetailBean.class);
        //.parseHaveHeaderJArray(baseBean,MyPointDetailBean.class,"list");
        if(lists == null){
            lists = new ArrayList<>();
        }
        adapter.setNewData(lists);
    }

    @Override
    public void error(String action, Throwable e) {

    }

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_integraldetail;
    }

    @Override
    protected void findViews() {
        iv_back = getView(R.id.img_back);
        recyclerView = getView(R.id.rcy_point);
    }

    @Override
    protected void formatViews() {
        iv_back.setOnClickListener(this);
    }

    @Override
    protected void formatData() {
//        for (int i=0;i<10;i++){
//            MyPointDetailBean bean = new MyPointDetailBean();
//            bean.setTime("2018-8-"+i);
//            bean.setTitle("答题"+i);
//            bean.setPoints("+11");
//            lists.add(bean);
//        }
        //创建布局管理
        LinearLayoutManager layoutManager = new LinearLayoutManager(this.context);
        layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        recyclerView.setLayoutManager(layoutManager);

        //创建适配器
        adapter = new MyPointsDeatilAdapter(this.getActivity(),R.layout.item_my_pointdetail,lists);

        //给RecyclerView设置适配器
        recyclerView.setAdapter(adapter);
        loaddata();
    }
    private void loaddata(){
        post("personal/scoreList", new HashMap(), BaseBean.class, false);
    }
    @Override
    protected void getBundle() {

    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.img_back:
                ((MineFragment)(this.getParentFragment())).GojumpMyPointsFragment();
                break;
        }
    }

    @Override
    public void onHiddenChanged(boolean hidden) {
        super.onHiddenChanged(hidden);
        if(!hidden){
            loaddata();
        }
    }
}
